package cn.tedu.tmall.front.content.controller;

import cn.tedu.tmall.common.web.JsonResult;
import cn.tedu.tmall.front.content.pojo.vo.ArticleItemVO;
import cn.tedu.tmall.front.content.pojo.vo.ArticleVO;
import cn.tedu.tmall.front.content.pojo.vo.PageDataVO;
import cn.tedu.tmall.front.content.service.IArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Tag(name="文章接口")
@Validated
@Slf4j
public class ArticleController {
    @Autowired
    private IArticleService articleService;
    @GetMapping("list")
    @Operation(summary = "按照分类id查找文章类别 ")
    public JsonResult listArticleByCategoryId(@RequestParam("categoryId") Long categoryId,
                                              @RequestParam("pageNum") Integer pageNum,
                                              @RequestParam ("pageSize") Integer pageSize) {
        PageDataVO<ArticleItemVO> articleItemVOList =
                articleService.listArticleByCategoryId(categoryId,pageNum,pageSize);
        return JsonResult.ok(articleItemVOList);

    }



    @GetMapping("detail/{articleId}")
    @Operation(summary = "按照文章id查找 ")
    @Parameters(
            @Parameter(
                    name = "articleId",
                    description = "文章id",
                    required = true,
                    example = "200",
                    schema = @Schema(
                            type = "integer", // 对应Java的Integer类型
                            format = "int64", // 明确整数格式（32位）
                            minimum = "1" // 约束最小值（可选，根据业务需求）
                    )
            )
    )
    public JsonResult getArticleById(@PathVariable Long articleId) {
        log.debug("通过文章id查询文章的列表,入参:{}",articleId);
        ArticleVO articleVO = articleService.getArticleById(articleId);
        return JsonResult.ok(articleVO);
    }



}
